'\" t
.TH "SD_EVENT_RUN" "3" "" "systemd 257.1" "sd_event_run"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
sd_event_run, sd_event_loop \- Run an event loop
.SH "SYNOPSIS"
.sp
.ft B
.nf
#include <systemd/sd\-event\&.h>
.fi
.ft
.HP \w'int\ sd_event_run('u
.BI "int sd_event_run(sd_event\ *" "event" ", uint64_t\ " "usec" ");"
.HP \w'int\ sd_event_loop('u
.BI "int sd_event_loop(sd_event\ *" "event" ");"
.SH "DESCRIPTION"
.PP
\fBsd_event_run()\fR
may be used to run a single iteration of the event loop specified in the
\fIevent\fR
parameter\&. The function waits until an event to process is available, and dispatches the registered handler for it\&. The
\fIusec\fR
parameter specifies the maximum time (in microseconds) to wait for an event\&. Use
\fB(uint64_t) \-1\fR
to specify an infinite timeout\&.
.PP
\fBsd_event_loop()\fR
invokes
\fBsd_event_run()\fR
in a loop, thus implementing the actual event loop\&. The call returns as soon as exiting was requested using
\fBsd_event_exit\fR(3)\&.
.PP
The event loop object
\fIevent\fR
is created with
\fBsd_event_new\fR(3)\&. Events sources to wait for and their handlers may be registered with
\fBsd_event_add_io\fR(3),
\fBsd_event_add_time\fR(3),
\fBsd_event_add_signal\fR(3),
\fBsd_event_add_child\fR(3),
\fBsd_event_add_defer\fR(3),
\fBsd_event_add_post\fR(3)
and
\fBsd_event_add_exit\fR(3)\&.
.PP
For low\-level control of event loop execution, use
\fBsd_event_prepare\fR(3),
\fBsd_event_wait\fR(3)
and
\fBsd_event_dispatch\fR(3)
which are wrapped by
\fBsd_event_run()\fR\&. Along with
\fBsd_event_get_fd\fR(3), these functions allow integration of an
\fBsd-event\fR(3)
event loop into foreign event loop implementations\&.
.SH "RETURN VALUE"
.PP
On failure, these functions return a negative errno\-style error code\&.
\fBsd_event_run()\fR
returns a positive, non\-zero integer if an event source was dispatched, and zero when the specified timeout hit before an event source has seen any event, and hence no event source was dispatched\&.
\fBsd_event_loop()\fR
returns the exit code specified when invoking
\fBsd_event_exit()\fR\&.
.SS "Errors"
.PP
Returned errors may indicate the following problems:
.PP
\fB\-EINVAL\fR
.RS 4
The
\fIevent\fR
parameter is invalid or
\fBNULL\fR\&.
.RE
.PP
\fB\-EBUSY\fR
.RS 4
The event loop object is not in the right state (see
\fBsd_event_prepare\fR(3)
for an explanation of possible states)\&.
.RE
.PP
\fB\-ESTALE\fR
.RS 4
The event loop is already terminated\&.
.RE
.PP
\fB\-ECHILD\fR
.RS 4
The event loop has been created in a different process, library or module instance\&.
.RE
.PP
Other errors are possible, too\&.
.SH "NOTES"
.PP
Functions described here are available as a shared library, which can be compiled against and linked to with the
\fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
file\&.
.PP
The code described here uses
\fBgetenv\fR(3), which is declared to be not multi\-thread\-safe\&. This means that the code calling the functions described here must not call
\fBsetenv\fR(3)
from a parallel thread\&. It is recommended to only do calls to
\fBsetenv()\fR
from an early phase of the program when no other threads have been started\&.
.SH "HISTORY"
.PP
\fBsd_event_run()\fR
and
\fBsd_event_loop()\fR
were added in version 220\&.
.SH "SEE ALSO"
.PP
\fBsystemd\fR(1), \fBsd-event\fR(3), \fBsd_event_new\fR(3), \fBsd_event_add_io\fR(3), \fBsd_event_add_time\fR(3), \fBsd_event_add_signal\fR(3), \fBsd_event_add_child\fR(3), \fBsd_event_add_inotify\fR(3), \fBsd_event_add_defer\fR(3), \fBsd_event_exit\fR(3), \fBsd_event_get_fd\fR(3), \fBsd_event_wait\fR(3), \m[blue]\fBGLib Main Event Loop\fR\m[]\&\s-2\u[1]\d\s+2
.SH "NOTES"
.IP " 1." 4
GLib Main Event Loop
.RS 4
\%https://developer.gnome.org/glib/unstable/glib-The-Main-Event-Loop.html
.RE
